package bb.lanxing.lib.devices.utils;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import com.dsi.ant.plugins.antplus.pcc.defines.DeviceType;

import bb.lanxing.lib.devices.api.SmartDevice;

public class AntPlusUtils {

    public static int getDeviceTypeForAntPlus(DeviceType deviceType) {
        if (deviceType == DeviceType.HEARTRATE) {
            return SmartDevice.TYPE_HEARTRATE;
        } else if (deviceType == DeviceType.BIKE_CADENCE) {
            return SmartDevice.TYPE_CADENCE;
        } else {
            return SmartDevice.TYPE_UNKNOW;
        }
    }

    public static boolean hasAntPlus(Context context) {
        PackageManager packageManager = context.getPackageManager();
        try {
            ApplicationInfo applicationInfo = packageManager.getApplicationInfo("com.dsi.ant.service.socket", 0);
            ApplicationInfo applicationInfo2 = packageManager.getApplicationInfo("com.dsi.ant.plugins.antplus", 0);
            if (applicationInfo.enabled) {
                return applicationInfo2.enabled;
            } else {
                return false;
            }
        } catch (PackageManager.NameNotFoundException unused) {
            return false;
        }
    }

    public static boolean isAntPlusAvailable(Context context) {
        return hasAntPlus(context);
    }
}
